﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using University.Workshop.DataAccess;
using System.Threading;
using System.Globalization;
using University.Workshop.DataAccess.LanguagePack.ClientLanguagePack;

namespace University.Workshop.Business
{
   public class Validate
    {
       private string ValidateUser;
       string language;
       public bool ValidateUserName(string user,string languageReceived)
       {
           language = languageReceived;
           Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
           ValidateUser = user;
           if (!String.IsNullOrEmpty(ValidateUser))
           {
               if (ValidateUser.Contains(" "))
                   return false;
           }
               return true;
           
       }
       public string ValidateUserLength(string user)
       {
           ValidateUser = user;
           if(user==null)
               throw new ArgumentNullException("user");
           if (ValidateUser.Length < 6)
               return ClientLanguagePack.ValidatePassword1;
           if (ValidateUser.Length > 20)
               return ClientLanguagePack.ValidatePassword2;
           return " ";
       }
       public bool ValidatePassword(string password)
       {
           
           if(password==null)
               throw new ArgumentNullException("password");
           ValidateUser = password;
           string passwordPattern = "\\w{5,30}";
           string passwordPattern1 = "\\d+";
           if (!(Regex.IsMatch(ValidateUser, passwordPattern) &&
               Regex.IsMatch(password, passwordPattern1)) || password.Length < 6 )
           {
               return false;
           }
           return true;
       }
       public bool ValidateEmail(string email)
       {
           string expression = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
         @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
         @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
           ValidateUser = email;
           if (Regex.IsMatch(ValidateUser, expression))
           {
               if (Regex.Replace(ValidateUser, expression, String.Empty).Length == 0)
               { return true; }
               else
               { return false; }
           }
           else
           { return false; }
       }
        
    }
}
